package com.edfu.core.commons.service.ws;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;

import com.edfu.core.commons.beans.EduObjectType;
import com.edfu.core.commons.beans.Notification;
import com.edfu.core.commons.service.api.INotificationService;

@Path("/")
@Produces( { MediaType.APPLICATION_JSON })
@Consumes(MediaType.APPLICATION_JSON)
@WebService(targetNamespace = "http://com.edfu.core.commons.service.ws.NotificationService")
public class NotificationServiceDelegate {
	
	@Autowired
	private INotificationService notificationService;
	
	@POST
	@Path("/notifications")
	@WebMethod(operationName = "addInterestsNotification")
	public Response addInterestsNotification(Notification notification) {
		notificationService.addInterestsNotification(notification);
		
		return Response.ok().build();
	}
	
	@POST
	@Path("/notifications/deleted/notificationId/{interestsNotificationId}/userId/{userId}")
	@WebMethod(operationName = "addDeletedInterestsNotification")
	public Response addDeletedInterestsNotification(@PathParam(value = "interestsNotificationId") long interestsNotificationId, @PathParam(value = "userId") String userId) {
		notificationService.addDeletedInterestsNotification(interestsNotificationId, userId);
		
		return Response.ok().build();
	}
	
	@DELETE
	@Path("/notifications/objectId/{objectId}/objectType/{objectType}")
	@WebMethod(operationName = "deleteInterestsNotification")
	public Response deleteInterestsNotification(@PathParam(value = "objectId") long objectId, @PathParam(value = "objectType") String objectType) {
		notificationService.deleteInterestsNotification(objectId, EduObjectType.valueOf(objectType));
		
		return Response.ok().build();
	}
	
	@GET
	@Path("/notifications/userId/{userId}")
	@WebMethod(operationName = "getActiveNotifications")
	public Response getActiveNotifications(@PathParam(value = "userId") String userId) {
		List<Notification> notifications = notificationService.getActiveNotifications(userId);
		return Response.ok(notifications).build();
	}

}
